package com.hllxd.hism.passport.login.gateway.dao.redis;

/**
 * @program: hllopen-rbac
 * @author: yuanhao
 * @description:
 * @create: 2020-05-12 15:21
 */
import com.hllxd.hism.passport.login.gateway.config.redis.RedisAdapter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: hllopen-rbac
 * @author: yuanhao
 * @description:
 * @create: 2020-05-12 11:29
 */
@Slf4j
@Service("authorityRedisMapper")
public class AuthorityRedisMapperImpl implements AuthorityRedisMapper {
  @Autowired private RedisAdapter redisAdapter;

  // 有效时间60分钟
  private static final long EXPIRE_TIME = 10 * 60 * 1000L;// 十分钟过期

//  // MIS AUTHORITY 前缀
  private static final String MIS_AUTHORITY_PREFIX = "hllxd:dycode:";

  // 拼接命名空间前缀
  private String getKey(Integer plat, String phoneNumber) {
    return MIS_AUTHORITY_PREFIX + phoneNumber + ":" + plat;
  }

//  @Override
//  public String getUserAuthority(String openID, String appKey, String userID, String rightType) {
//    return redisAdapter.getValue(getKey(openID, appKey, userID, rightType));
//  }
//
//  @Override
//  public void addUserAuthority(
//      String openID, String appKey, String userID, String rightType, String authority) {
//    redisAdapter.setValue(getKey(openID, appKey, userID, rightType), authority, EXPIRE_DATE);
//  }
//
//  @Override
//  public void delUserAuthority(String openID, String appKey, String userID, String rightType) {
//    redisAdapter.delKey(getKey(openID, appKey, userID, rightType));
//  }

  @Override public String getDyCode(Integer plat, String phoneNumber) {
    return redisAdapter.getValue(getKey(plat, phoneNumber));
  }

  @Override public String delDyCode(Integer plat, String phoneNumber) {
    redisAdapter.delKey(getKey(plat, phoneNumber));
    return null;
  }

  @Override public String setDyCode(Integer plat, String phoneNumber, String dyCode) {
    String key = getKey(plat, phoneNumber);
    redisAdapter.setValue(key, dyCode, EXPIRE_TIME);
    return key;
  }
}
